package cn.kent.heima.base.heap;

import java.util.ArrayList;
import java.util.List;

/**
 * 堆内存溢出举例:  java.lang.OutOfMemoryError: Java heap space
 * -Xmx8m --> 17
 * -Xmx2m --> 14
 */
@SuppressWarnings("all")
public class Demo_03 {
    public static void main(String[] args) {
        int i = 0;
        try {
            List<String> list = new ArrayList<>();
            String str = "hello";
            while (true) {
                list.add(str);
                str += str;
                i++;
            }
        } catch (Throwable e) {
            e.printStackTrace();
            System.out.println(i);
        }
    }
}
